﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.Threading;
using Sanctuary.Core.Images;

namespace Sanctuary.Core.Dialog
{
    public class DialogImageEnterAction : IDialogAction
    {
        private string name;
        private string emotion;
        private ImageLocation location;
        private ImageEnterTransition transition;
        private bool flipped;

        public void StartAction()
        {
            Image image = GameFile.MainImageControls.GetImageItem(location, flipped);
            if (location == ImageLocation.Background)
            {
                GameFile.GameBackgrounds.LoadBackground(image, name);
            }
            else
            {
                GameFile.GameCharacters.LoadEmotion(image, name, emotion);
            }
            
            image.ImageOpened += new EventHandler<RoutedEventArgs>(image_ImageOpened);
        }

        void image_ImageOpened(object sender, RoutedEventArgs e)
        {
            GameFile.MainImageControls.TransitionEnterImage(location, transition);
        }

        public bool WaitForInput
        {
            get { return false; }
        }

        public void LoadFromXElement(XElement element)
        {
            name = element.Value;
            Enum.TryParse<ImageLocation>(element.Attribute("ImageLocation").Value, out location);
            Enum.TryParse<ImageEnterTransition>(element.Attribute("Transition").Value, out transition);
            emotion = element.Attribute("Emotion").Value;
            flipped = bool.Parse(element.Attribute("Flipped").Value);
        }
    }
}
